package com.wx.mall.operate.controller;


import com.wx.mall.common.api.CommonResult;
import com.wx.mall.operate.dto.SeckillTimeDto;
import com.wx.mall.operate.entity.SeckillTime;
import com.wx.mall.operate.service.impl.SeckillTimeServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author j
 * @since 2020-05-28
 */
@RestController
@RequestMapping("/seckill/time")
public class SeckillTimeController {

    @Autowired
    SeckillTimeServiceImpl seckillTimeService;

    @ApiOperation(value = "查询全部")
    @GetMapping("/getFindTime")
    public CommonResult<List<SeckillTime>> getFindTimeList(){
        List<SeckillTime> list=seckillTimeService.findTime();
        return CommonResult.success(list);
    }

    @ApiOperation(value = "查询全部2")
    @GetMapping("/getFindTimeTwo")
    public CommonResult<List<SeckillTime>> getFindTimeTwoList(){
        List<SeckillTime> list=seckillTimeService.findTimeTwo();
        return CommonResult.success(list);
    }

    @ApiOperation(value = "修改编辑")
    @PutMapping("/getSeckillUpdate")
    public CommonResult<Integer> getUpdateList(SeckillTimeDto dto){
        System.out.println(dto);
        int i = seckillTimeService.updateTimeList(dto);
        return i==1?CommonResult.success():CommonResult.failed();
    }

    @ApiOperation(value = "添加保存")
    @PostMapping("/getSaveTime")
    public CommonResult<Integer> getSaveList(SeckillTimeDto dto){
        int i = seckillTimeService.addTimeList(dto);
        return i==1?CommonResult.success():CommonResult.failed();
    }

    @ApiOperation(value = "软删除")
    @DeleteMapping("/deleteTime")
    public CommonResult<Integer> getDeletesList(Integer id){
        System.out.println(id);
        int success=seckillTimeService.deletes(id);
        return success==1?CommonResult.success():CommonResult.failed();
    }

}

